home *** CD-ROM | disk | FTP | other *** search
- #include <aes.h>
- #include <stdio.h>
- #include <tos.h>
- #include <ctype.h>
- #include <string.h>
- #include <stdlib.h>
- #include <strins.c>
-
- #include "splitit.h"
- extern int rs_trloc[];
- extern OBJECT *rs_trindex[];
- extern void fix_objects(void);
- extern char p_to_nul[];
- extern TEDINFO rs_tedinfo[];
- extern ICONBLK rs_iconblk[];
- extern int bbk000[];
- extern BITBLK rs_bitblk[];
- extern OBJECT rs_object[];
-
- #define SHOW 1
- #define HIDE 0
- #define TRUE 1
- #define FALSE 0
- #define READ 0
- #define WRITE 1
- /**************************************
- Message to user in (c)
- ***************************************/
- void mess(char *c)
- {
- char a[40];
-
- graf_mouse(ARROW,0);
- strcpy(a,"[3][");
- strcat(a,c);
- strcat(a,"][OK]");
- form_alert(1,a);
- graf_mouse(POINT_HAND,0);
- }
-
- int mess2(
- char *c1, /* Line one of message */
- char *c2, /* Line two */
- char *b1, /* Button one text */
- char *b2, /* Button two text */
- int db ) /* Default Button # */
- {
- char a[80];
-
- graf_mouse(ARROW,0);
- strcpy(a,"[2][");
- strcat(a,c1);
- strcat(a,"|");
- strcat(a,c2);
- strcat(a,"][");
- strcat(a,b1);
- strcat(a,"|");
- strcat(a,b2);
- strcat(a,"]");
- db = form_alert(db+1,a) - 1;
- graf_mouse(POINT_HAND,0);
- return(db);
- }
-
-
- void messi(int i)
- {
- char m[16];
- sprintf(m,"%d",i);
- mess(m);
- }
-
- void messl(long l)
- {
- char m[16];
- sprintf(m,"%ld",l);
- mess(m);
- }
-
- /*******************************
- GEM Related Functions
- *******************************/
-
- /***********************************
- Will put dialog box on screen
- and return exit object after
- erasing it.
- ***********************************/
- void erase_dialog(
- int x,
- int y,
- int w,
- int h )
- {
- int sx,sy;
- sx=x+(w/2);
- sy=y+(h/2);
- form_dial(FMD_SHRINK,sx,sy,0,0,x,y,w,h);
- form_dial(FMD_FINISH,sx,sy,0,0,x,y,w,h);
- }
-
- #define DDRC 0
- #define DDRN 1
- #define DDRS 2
- #define DDRW 4
- #define DDRE 8
- void draw_dialog(
- int box_ind,
- int *x,
- int *y,
- int *w,
- int *h,
- int place, /* 1-N,2-S,4-W,8-E,15-C,5-NW,6-SW,9-NE,10-SE */
- char draw )
- {
- int sx,sy;
-
- form_center(rs_trindex[box_ind],x,y,w,h);
- *x += (160*(((place & DDRE)/DDRE)-((place & DDRW)/DDRW)));
- *y += (100*(((place & DDRS)/DDRS)-((place & DDRN)/DDRN)));
- sx=*x+(*w/2);
- sy=*y+(*h/2);
-
- form_dial(FMD_START,sx,sy,0,0,*x,*y,*w,*h);
- form_dial(FMD_GROW,sx,sy,0,0,*x,*y,*w,*h);
- if (draw) objc_draw(rs_trindex[box_ind],0,10,*x,*y,*w,*h);
- }
-
- void dial_draw(
- int box_ind,
- int obj )
- {
- int x1,y1;
- OBJECT *redraw;
-
- redraw = &rs_object[rs_trloc[box_ind]+obj];
- objc_offset(rs_trindex[box_ind],obj,&x1,&y1);
- objc_draw(rs_trindex[box_ind],0,10,x1,y1,redraw->ob_width,redraw->ob_height);
- }
-
- int exit_dialog(
- int box_ind,
- int x,
- int y,
- int w,
- int h,
- int draw )
- {
- int e;
-
- if (draw) objc_draw(rs_trindex[box_ind],0,10,x,y,w,h);
- e = form_do(rs_trindex[box_ind],0);
- rs_object[rs_trloc[box_ind]+e].ob_state &= UNSELECT;
- dial_draw(box_ind,e);
- return(e);
- }
-
- void redraw_dialog(
- int box_ind,
- int x,
- int y,
- int w,
- int h )
- {
- objc_draw(rs_trindex[box_ind],0,10,x,y,w,h);
- }
-
- void dial2_draw(
- int box_ind,
- int obj1,
- int obj2 )
- {
- int x1,y1;
- int x2,y2;
- int w,h;
- OBJECT *redraw1,*redraw2;
-
- redraw1 = &rs_object[rs_trloc[box_ind]+obj1];
- redraw2 = &rs_object[rs_trloc[box_ind]+obj2];
- objc_offset(rs_trindex[box_ind],obj1,&x1,&y1);
- objc_offset(rs_trindex[box_ind],obj2,&x2,&y2);
- w = x2-x1+redraw2->ob_width;
- h = y2-y1+redraw2->ob_height;
- if (w < redraw1->ob_width) w = redraw1->ob_width;
- if (h < redraw1->ob_height) h = redraw1->ob_height;
- objc_draw(rs_trindex[box_ind],0,10,x1,y1,w,h);
- }
-
- /*******************************
- Select a file
- *******************************/
- int fileselect(
- char *s,
- char *ext )
- {
- char p[64];
- int n;
- int drv;
-
- drv = Dgetdrv();
- Dgetpath(p,0);
- if (p[0] != '\\') strinc(p,0,'\\');
- strins(p,0,"A:");
- while (drv > 0)
- {
- --drv;
- ++p[0];
- }
- if (p[strlen(p)-1] != '\\') strcat(p,"\\");
- strcat(p,ext);
- graf_mouse(ARROW,0);
- fsel_input(p,s,&n);
- graf_mouse(POINT_HAND,0);
- if (strrchr(p,'\\') != strchr(p,'\\'))
- *(strrchr(p,'\\')) = 0x0;
- else
- *(strrchr(p,'\\')+1) = 0x0;
- while (*p > 'A')
- {
- --p[0];
- ++drv;
- }
- Dsetdrv(drv);
- Dsetpath(p+2);
- return(n);
- }
-
- /**************************
- Create buffer of
- size bytes or a fraction
- thereof
- **************************/
- void *mport(
- unsigned long wanted,
- unsigned long *received
- )
- {
- void *buf;
- *received = wanted;
- while ((buf = malloc(*received))==NULL)
- *received /= 2;
- return(buf);
- }
-
- /**************************
- Show file and length
- in COPY dialog
- **************************/
- void dial_file(
- char *name,
- long length,
- int x,
- int y,
- int w,
- int h
- )
- {
- strncpy((char *)rs_object[rs_trloc[FILEDIAL]+FILENAME].ob_spec,name,16);
- sprintf((char *)rs_object[rs_trloc[FILEDIAL]+FILESIZE].ob_spec,"%ld\0",length);
- redraw_dialog(FILEDIAL,x,y,w,h);
- }
-
- /**************************
- Input K size to split
- file into
- **************************/
- unsigned long dialk(void)
- {
- int x,y,w,h;
- int k=0;
-
- draw_dialog(SIZEDIAL,&x,&y,&w,&h,DDRC,HIDE);
- while (k==0)
- {
- exit_dialog(SIZEDIAL,x,y,w,h,SHOW);
- k = atoi(((TEDINFO *)(rs_object[rs_trloc[SIZEDIAL]+SIZEEXIT].ob_spec))->te_ptext);
- }
- erase_dialog(x,y,w,h);
- return((unsigned long)k);
- }
-
- /***************************
- Open a new file
- ***************************/
- int create(char *name)
- {
- if (Fsfirst(name,7)>=0)
- {
- Fgetdta();
- if (mess2("Overwrite file?",name,"Nay","Yeah",1))
- Fdelete(name);
- else
- return(0);
- }
- Fclose(Fcreate(name,0));
- return(1);
- }
-
- /**************************
- Split file
- **************************/
- void split(void)
- {
- static char *name = "FILENAME.EXT";
- static char *ext = "*.*\0 ";
- DTA *dta;
- int x,y,w,h,fd,fds;
- int p,drv;
- char filename[16];
- unsigned long size,bsize,i,j,k,iold;
- char sifile[16],path[64];
- void *buf;
-
- i = 0;
- if (fileselect(name,ext))
- if (Fsfirst(name,7)>=0)
- {
- dta = Fgetdta();
- size = dta->filesize;
- strcpy(filename,dta->filename);
- k = dialk();
- drv = Dgetdrv();
- Dgetpath(path,0);
- if (path[0] != '\\')
- strinc(path,0,'\\');
- fds=Fopen(filename,READ);
- mess("Select destination path");
- fileselect(name,ext);
- draw_dialog(FILEDIAL,&x,&y,&w,&h,DDRC,HIDE);
- dial_file(filename,size,x,y,w,h);
- buf = mport(k*1024L,&bsize);
- sprintf(sifile,"SI_");
- for (p=3;(p<9)&&(filename[p-3]!='.')&&(filename[p-3]!='\0');p++)
- sifile[p] = filename[p-3];
- for (j=0;j<((size/(k*1024L))+1);j++)
- {
- sprintf(sifile+p-1,".%3ld\0",j);
- if (j<100)
- {
- *(sifile+p)='0';
- if (j<10)
- *(sifile+p+1)='0';
- }
- if ((i+(k*1024))>size)
- dial_file(sifile,size-i,x,y,w,h);
- else
- dial_file(sifile,1024L * k,x,y,w,h);
- fd=Fcreate(sifile,0);
- Fclose(fd);
- fd=Fopen(sifile,WRITE);
- if (j==0)
- Fwrite(fd,16,filename);
- iold = i;
- while (i < (iold+(k*1024)))
- {
- if ((i+bsize)>size)
- {
- Fread(fds,size-i,buf);
- Fwrite(fd,size-i,buf);
- }
- else
- {
- Fread(fds,bsize,buf);
- Fwrite(fd,bsize,buf);
- }
- i += bsize;
- }
- Fclose(fd);
- }
- Fclose(fds);
- Dsetdrv(drv);
- Dsetpath(path);
- if (mess2("Erase original",filename,"Nay","Yeah",1))
- Fdelete(filename);
- erase_dialog(x,y,w,h);
- free(buf);
- }
- }
-
- /**************************
- Join files
- **************************/
- void join(void)
- {
- static char *name = "FILENAME.EXT";
- static char *ext = "SI_?????.000";
- DTA *dta;
- int x,y,w,h,fd,fds;
- int j;
- char filename[16];
- long size;
- char sifile[16];
- char *p;
- void *buf;
- char spath[64],dpath[64];
- int sdrv,ddrv;
- int dflag;
-
- if (fileselect(name,ext))
- {
- sdrv = Dgetdrv();
- Dgetpath(spath,0);
- if (spath[0] != '\\')
- strinc(spath,0,'\\');
- draw_dialog(FILEDIAL,&x,&y,&w,&h,DDRC,HIDE);
- strcpy(sifile,name);
- mess("Select destination path");
- if (fileselect(name,ext))
- {
- ddrv = Dgetdrv();
- Dgetpath(dpath,0);
- if (dpath[0] != '\\')
- strinc(dpath,0,'\\');
- p = strchr(sifile,'.');
- dflag = mess2("Delete pieces as","they are used?","Nay","Yeah",1);
- for (j=0;;j++)
- {
- sprintf(p,".%3d\0",j);
- if (j<100)
- {
- *(p+1)='0';
- if (j<10)
- *(p+2)='0';
- }
- Dsetdrv(sdrv);
- Dsetpath(spath);
- if (Fsfirst(sifile,7)>=0)
- {
- dta = Fgetdta();
- size = dta->filesize;
- buf = malloc(size);
- dial_file(sifile,size,x,y,w,h);
- Dsetdrv(sdrv);
- Dsetpath(spath);
- fds=Fopen(sifile,READ);
- Dsetdrv(ddrv);
- Dsetpath(dpath);
- if (j==0)
- {
- Fread(fds,16,filename);
- if (!create(filename))
- {
- erase_dialog(x,y,w,h);
- return;
- }
- }
- fd=Fopen(filename,WRITE);
- Fseek(0,fd,2);
- if (j == 0)
- {
- Fread(fds,size-16,buf);
- Fwrite(fd,size-16,(char *)buf);
- }
- else
- {
- Fread(fds,size,buf);
- Fwrite(fd,size,buf);
- }
- Fclose(fd);
- Fclose(fds);
- free(buf);
- if (dflag)
- {
- Dsetdrv(sdrv);
- Dsetpath(spath);
- Fdelete(sifile);
- }
- }
- else
- {
- erase_dialog(x,y,w,h);
- return;
- }
- }
- }
- erase_dialog(x,y,w,h);
- }
- }
-
- /*************************
- BINC: convert binary
- to C source code
- **************************/
- void binc(void)
- {
- static char *sname = "FILENAME.EXT";
- static char dname[16];
- static char *ext = "*.*\0 ";
- static char *dext = "*.C\0 ";
- char path[64];
- int drv,fd,fds,i,j;
- int buf[6],x,y,w,h;
- char *line = " 0x1234,0x1234,0x1234,0x1234,0x1234,0x1234 /* 00000 ABCDEFGHIJKL */\015\012";
- DTA *dta;
- unsigned long size,ds,ls,count;
- char *cbuf;
-
- line[0] = '\011';
- cbuf = (char *)buf;
- ls = strlen(line);
- if (fileselect(sname,ext))
- {
- drv = Dgetdrv();
- Dgetpath(path,0);
- if (path[0] != '\\')
- strinc(path,0,'\\');
- strcpy(dname,sname);
- *(strchr(dname,'.')+1)='C';
- *(strchr(dname,'.')+2)='\0';
- mess("Select destination path");
- if (fileselect(dname,dext))
- if (create(dname))
- {
- fd = Fopen(dname,WRITE);
- Dsetdrv(drv);
- Dsetpath(path);
- if (Fsfirst(sname,7)>=0)
- {
- dta = Fgetdta();
- size = dta->filesize;
- draw_dialog(FILEDIAL,&x,&y,&w,&h,DDRC,HIDE);
- dial_file(sname,size,x,y,w,h);
- fds = Fopen(sname,READ);
- *strchr(sname,'.') = '\0';
- ds = 12 + strlen(sname);
- Fwrite(fd,4,"int ");
- Fwrite(fd,strlen(sname),sname);
- Fwrite(fd,8,"[] = {\015\012");
- dial_file(dname,ds,x,y,w,h);
- count = 0;
- while (size != 0)
- {
- if (size<12)
- {
- Fread(fds,size,cbuf);
- j = (unsigned int)(size+1) / 2;
- size = 0;
- }
- else
- {
- Fread(fds,12,cbuf);
- j = 6;
- size -= 12;
- }
- for(i=0;i<j;i++)
- {
- sprintf(line+3+i*7,"%4x",buf[i]);
- if (buf[i]<0x1000)
- {
- *(line+3+i*7) = '0';
- if (buf[i] < 0x100)
- {
- *(line+4+i*7) = '0';
- if (buf[i]<0x10)
- *(line+5+i*7)= '0';
- }
- }
- *(line+(i+1)*7) = ',';
- if (isprint(*(cbuf+i*2)))
- *(line+52+i*2) = *(cbuf+i*2);
- else
- *(line+52+i*2) = '.';
- if (isprint(*(cbuf+i*2+1)))
- *(line+53+i*2) = *(cbuf+i*2+1);
- else
- *(line+53+i*2) = '.';
- }
- for(i=j;i<6;i++)
- {
- sprintf(line+i*7," ");
- *(line+(i+1)*7) = ' ';
- *(line+53+i*2) = ' ';
- *(line+54+i*2) = ' ';
- if (*(line-1+i*7) == ',')
- *(line-1+i*7) = ' ';
- }
- if (size == 0)
- *(line+42) = ' ';
- ds += ls;
- sprintf(line+46,"%5lx",count);
- *(line+51) = ' ';
- count += 12;
- dial_file(dname,ds-12-strlen(sname),x,y,w,h);
- Fwrite(fd,ls,line);
- }
- Fwrite(fd,3,"\011};");
- ds += 2;
- dial_file(dname,ds,x,y,w,h);
- erase_dialog(x,y,w,h);
- Fclose(fds);
- }
- Fclose(fd);
- }
- }
- }
-
- /*************************
- Do help dialog
- **************************/
- void infohelp(void)
- {
- int x,y,w,h;
- draw_dialog(HELPDIAL,&x,&y,&w,&h,0,SHOW);
- exit_dialog(HELPDIAL,x,y,w,h,HIDE);
- erase_dialog(x,y,w,h);
- }
-
- /****************************
- Do info dialog
- ****************************/
- void maininfo(void)
- {
- int x,y,w,h;
- int selection;
-
- draw_dialog(INFODIAL,&x,&y,&w,&h,DDRN|DDRS|DDRE|DDRW,SHOW);
- selection = exit_dialog(INFODIAL,x,y,w,h,HIDE);
- erase_dialog(x,y,w,h);
- if (selection == INFOHELP)
- infohelp();
- }
-
- /*******************************************************************
- MAIN
- *******************************************************************/
- main()
- {
- int msg_buf[8];
-
- /* INITIALIZE GEM */
- appl_init();
- fix_objects();
-
- /* APPLICATION ROUTINES */
- graf_mouse(POINT_HAND,0);
- maininfo();
- menu_bar(rs_trindex[MAINMENU],SHOW);
- for (;;)
- {
- evnt_mesag(msg_buf);
- if (msg_buf[0] != MN_SELECTED) continue;
- if (msg_buf[4] == MAINQUIT) break;
-
- switch (msg_buf[4])
- {
- case MAININFO:
- maininfo();
- break;
- case MAINSPLIT:
- split();
- break;
- case MAINJOIN:
- join();
- break;
- case MAINBINC:
- binc();
- break;
- default:
- break;
- }
- menu_tnormal(rs_trindex[MAINMENU],msg_buf[3],TRUE);
- }
- menu_bar(rs_trindex[MAINMENU],HIDE);
- appl_exit();
- return(0);
- }
-